﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Maticsoft.DBUtility;

namespace RLZY.others
{
    class role
    {
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet Getrole()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct roleid ");
            strSql.Append(" FROM userpassword order by roleid");

            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得子菜单
        /// </summary>
        public DataSet GetChrole(string fumame)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM tb_menu ");
            strSql.Append("where  fmuname=@父菜单");

            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@父菜单",fumame),
            };

            return DbHelperSQL.Query(strSql.ToString(), param);
        }
        /// <summary>
        /// 是否重复 
        /// </summary>
        public bool isExits(int roleid, int menuid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM tb_rolemenu ");
            strSql.Append("where  roleid=@roleid");
            strSql.Append(" and  menuid=@menuid");
            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@roleid",roleid),
                new SqlParameter("@menuid" ,menuid),

            };

            SqlDataReader dr = DbHelperSQL.ExecuteReader(strSql.ToString(), param);
            if (dr.Read()) { return true; }
            else { return false; }
        }
        /// <summary>
        /// 获得权限菜单
        /// </summary>
        public DataSet GetIDrole(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM tb_rolemenu ");
            strSql.Append("where  roleid=@roleid");

            SqlParameter[] param = new SqlParameter[] 
            { 
                new SqlParameter("@roleid",id),
            };

            return DbHelperSQL.Query(strSql.ToString(), param);
        }
    }
}
